//
//  LGOrderConfirmTableCell.m
//  HeartDisease_YHJK
//
//  Created by 1234 on 2025/2/19.
//

#import "LGOrderConfirmTableCell.h"

@interface LGOrderConfirmTableCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIImageView *iconView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *statusLabel;
/**   */
@property (nonatomic , strong)UIView *lineView;
/**   */
@property (nonatomic , strong)UIImageView *headPic;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UIButton *doctorBtn;
/**   */
@property (nonatomic , strong)UILabel *hospitalLabel;
/**   */
@property (nonatomic , strong)UILabel *ageLabel;
/**   */
@property (nonatomic , strong)UIButton *timeBtn;
/**   */
@property (nonatomic , strong)UILabel *priceLabel;
/**  退款时间和金额 */
@property (nonatomic , strong)UIButton *refundBtn;
@property (nonatomic , strong)UILabel *refundPrice;

@end

@implementation LGOrderConfirmTableCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.showRefund = NO;
        [self createSubView];
    }
    return  self;
}

-(void)setShowRefund:(BOOL)showRefund{
    _showRefund = showRefund;
    self.refundBtn.hidden = !showRefund;
    self.refundPrice.hidden = !showRefund;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(-viewPix(20));
    }];
    self.iconView.hidden = YES;
    self.titleLabel.text = LGNSString(dataDic[@"bus_name"]);
    self.statusLabel.text = LGNSString(dataDic[@"pay_state_name"]);
    self.statusLabel.textColor = [UIColor colorWithString:@"#3291FF"];
    UIImage *placeHolder = [LGNSString(dataDic[@"gender"]) isEqualToString:@"男"]?defaultPatientMan:defaultPatientWomen;
    [self.headPic sd_setImageWithURL:[NSURL URLWithString:dataDic[@"avatar_url"]] placeholderImage:placeHolder];
    self.nameLabel.text = LGNSString(dataDic[@"patient_name"]);
    NSString *doctorName = LGNSString(dataDic[@"doctor_name"]);
    CGFloat width = [doctorName textWidthWithFont:LGFontWeight(12, UIFontWeightMedium) maxHeight:MAXFLOAT];
    width = (doctorName.length>0)?width+viewPix(35):0;
    [self.doctorBtn mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(width));
    }];
    [self.doctorBtn setTitle:doctorName forState:UIControlStateNormal];
    self.doctorBtn.hidden = (doctorName.length>0)?NO:YES;
    self.hospitalLabel.text = LGNSString(dataDic[@"level_title"]);
    self.ageLabel.text = [NSString stringWithFormat:@"%@ %@岁",dataDic[@"gender"],dataDic[@"age"]];
    [self.timeBtn setTitle:[NSString stringWithFormat:@" 订单时间：%@",dataDic[@"create_time"]] forState:UIControlStateNormal];
    self.priceLabel.text = [NSString stringWithFormat:@"¥ %@",dataDic[@"paid_amount"]];
    
    [self.refundBtn setTitle:[NSString stringWithFormat:@" 退款时间：%@",dataDic[@"refund_time"]] forState:UIControlStateNormal];
    self.refundPrice.text = [NSString stringWithFormat:@"¥ %@",dataDic[@"refund_amount"]];
}



-(void)createSubView{
    self.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.baseView];
    [self.baseView addSubview:self.iconView];
    [self.baseView addSubview:self.titleLabel];
    [self.baseView addSubview:self.statusLabel];
    [self.baseView addSubview:self.lineView];
    [self.baseView addSubview:self.headPic];
    [self.baseView addSubview:self.nameLabel];
    [self.baseView addSubview:self.doctorBtn];
    [self.baseView addSubview:self.hospitalLabel];
    [self.baseView addSubview:self.ageLabel];
    [self.baseView addSubview:self.timeBtn];
    [self.baseView addSubview:self.priceLabel];
    [self.baseView addSubview:self.refundBtn];
    [self.baseView addSubview:self.refundPrice];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(6));
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.bottom.equalTo(self.contentView).offset(-viewPix(10));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(viewPix(6));
        make.right.lessThanOrEqualTo(self.statusLabel.mas_left).offset(-viewPix(5));
        make.centerY.equalTo(self.iconView);
    }];
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.iconView);
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headPic.mas_right).offset(viewPix(8));
        make.top.equalTo(self.headPic);
    }];
    
    [self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(viewPix(5));
        make.centerY.equalTo(self.nameLabel);
    }];
    
    [self.doctorBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(viewPix(7));
        make.left.equalTo(self.nameLabel);
        make.width.equalTo(@(viewPix(70)));
        make.height.equalTo(@(viewPix(20)));
    }];
    
    [self.hospitalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.doctorBtn.mas_right).offset(viewPix(5));
        make.right.lessThanOrEqualTo(self.baseView).offset(-viewPix(5));
        make.centerY.equalTo(self.doctorBtn);
    }];
    
    
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.timeBtn);
    }];
    
    [self.refundPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.refundBtn);
    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc]initWithFrame:CGRectMake(viewPix(12), viewPix(12), viewPix(20), viewPix(20))];
    }
    return _iconView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"专家咨询" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:2];
    }
    return _titleLabel;
}

-(UILabel *)statusLabel{
    if(!_statusLabel){
        _statusLabel = [UILabel lableWithText:@"已完成" colorString:@"#999999" textFont:LGFontWeight(14, UIFontWeightMedium) textAlignment:NSTextAlignmentRight lines:1];
        [_statusLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    }
    return _statusLabel;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc]initWithFrame:CGRectMake(viewPix(12), viewPix(44), Screen_W-viewPix(32)-viewPix(24), 0.5)];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E8E8E8"];
    }
    return _lineView;
}

-(UIImageView *)headPic{
    if(!_headPic){
        _headPic = [[UIImageView alloc]initWithFrame:CGRectMake(viewPix(12), kMaxY(self.lineView.frame)+viewPix(12), viewPix(32), viewPix(32))];
        _headPic.cornerRidus = 5;
    }
    return _headPic;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _nameLabel;
}

-(UIButton *)doctorBtn{
    if(!_doctorBtn){
        _doctorBtn = [UIButton buttonWithTitle:@"" titleFont:LGFontWeight(12, UIFontWeightMedium) textColor:@"#56BEA0" imageName:@"药球患者-医生"];
        _doctorBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _doctorBtn.imageEdgeInsets = UIEdgeInsetsMake(0, viewPix(10), 0, 0);
        _doctorBtn.titleEdgeInsets = UIEdgeInsetsMake(0, viewPix(12), 0, 0);
        _doctorBtn.backgroundColor = [UIColor colorWithString:@"#EBF8F3"];
        _doctorBtn.userInteractionEnabled = NO;
        _doctorBtn.cornerRidus = viewPix(10);
    }
    return _doctorBtn;
}
-(UILabel *)hospitalLabel{
    if(!_hospitalLabel){
        _hospitalLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
        [_hospitalLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    }
    return _hospitalLabel;
}

-(UILabel *)ageLabel{
    if(!_ageLabel){
        _ageLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _ageLabel;
}

-(UIButton *)timeBtn{
    if(!_timeBtn){
        _timeBtn = [UIButton buttonWithTitle:@" 订单时间：" titleFont:LGFont(14) textColor:@"#666666" imageName:@"我的订单-订单时间"];
        _timeBtn.frame = CGRectMake(viewPix(12), kMaxY(self.headPic.frame)+viewPix(20), viewPix(250), viewPix(22));
        _timeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    }
    return _timeBtn;
}

-(UILabel *)priceLabel{
    if(!_priceLabel){
        _priceLabel = [UILabel lableWithText:@"" colorString:@"#3291FF" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _priceLabel;
}

-(UIButton *)refundBtn{
    if(!_refundBtn){
        _refundBtn = [UIButton buttonWithTitle:@" 退款时间：" titleFont:LGFont(14) textColor:@"#666666" imageName:@"我的订单-订单时间"];
        _refundBtn.frame = CGRectMake(viewPix(12), kMaxY(self.timeBtn.frame)+viewPix(3), viewPix(250), viewPix(22));
        _refundBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    }
    return _refundBtn;
}

-(UILabel *)refundPrice{
    if(!_refundPrice){
        _refundPrice = [UILabel lableWithText:@"" colorString:@"#3291FF" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _refundPrice;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
